/**
 * 
 */
package com.mobile2you.nci.android;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.mobile2you.nci.android.data.SqlHelper;
import com.mobile2you.nci.android.data.WebServicesRequest;
import com.mobile2you.nci.android.utils.Utils;

/**
 * @author JBromo
 * 
 */
public class Home extends Activity {
	private class LoaderTask extends AsyncTask<String, String, Boolean> {

		@Override
		protected Boolean doInBackground(String... params) {
			WebServicesRequest.checkUpdate(Home.this);
			return null;
		}
	}

	private void listenView() {

		View newsView = findViewById(R.id.view_news);
		newsView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Utils.lancerActiviter(Home.this, MenuNews.class);
			}
		});
		View centre = findViewById(R.id.view_centre);
		centre.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Utils.lancerActiviter(Home.this, MenuCentre.class);
			}
		});

		View annuaire = findViewById(R.id.view_annuaire);
		annuaire.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (SqlHelper.getInstance(v.getContext()).alreadyLogin()) {
					Utils.lancerActiviter(Home.this, MenuAnnuaireDetails.class);
				} else {
					Utils.lancerActiviter(Home.this, MenuAnnuaire.class);
				}

			}
		});

		View services = findViewById(R.id.view_services);
		services.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Utils.lancerActiviter(Home.this, MenuService.class);
			}
		});

		View contact = findViewById(R.id.view_contact);
		contact.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Utils.lancerActiviter(Home.this, MenuContact.class);
			}
		});
		View express = findViewById(R.id.view_express);
		express.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Utils.lancerActiviter(Home.this, MenuExpress.class);
			}
		});

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		listenView();
		new LoaderTask().execute();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onStart()
	 */
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Main.finishMain();
	}
}
